package 剑指offer;

/**
 * @ClassName _53在排序数组中查找数字
 * @Description TODO
 * @Author 昝亚杰
 * @Date 2022/2/25 20:22
 * Version 1.0
 **/
public class _53_I在排序数组中查找数字 {
    public int search(int[] nums, int target) {
        return helper(nums,target) - helper(nums,target - 1);
    }
    public int helper(int[] nums,int target){//二分查找
        int i = 0,j = nums.length;
        while (i <= j){
            int m = (i + j) / 2;
            if(nums[m] <= target){
                i = m + 1;
            }else{
                j = m - 1;
            }
        }
        return i;
    }
}
